<template>
  <el-table
    ref="multipleTable"
    :data="tableData"
    tooltip-effect="dark"
    style="width: 100%"
    :header-cell-style="{ background: '#f3f6fb', border: '0' }"
    :header-row-style="{ border: '0' }"
    :row-style="{ height: '30px' }"
    :cell-style="{ padding: '4px', border: '0' }"
    @selection-change="handleSelectionChange"
  >
    <el-table-column type="selection" width="55"> </el-table-column>
    <el-table-column type="index" label="序号" width="100"> </el-table-column>
    <el-table-column prop="innerCode" label="设备编号" width="160">
    </el-table-column>
    <el-table-column prop="type.name" label="设备型号" width="160">
    </el-table-column>
    <el-table-column prop="node.name" label="详细地址" show-overflow-tooltip>
    </el-table-column>
    <el-table-column prop="ownerName" label="合作商" show-overflow-tooltip>
    </el-table-column>
    <el-table-column
      :formatter="VmStatus"
      prop="vmStatus"
      label="设备状态"
      show-overflow-tooltip
    >
    </el-table-column>
    <el-table-column label="操作" show-overflow-tooltip>
      <template #default="{ row }">
        <el-button type="default" @click="$emit('updataAisle', row)"
          >货道</el-button
        >
        <el-button type="default" @click="$emit('isPolicy', row)"
          >策略</el-button
        >
        <el-button type="default" @click="$emit('updataPolicy', row)"
          >修改</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import Bus from '@/utils/bus'
import DeviceManagerEnum from '@/constant/device-manager'
export default {
  name: 'DeviceTable',
  props: {
    tableData: {
      type: Array,
      required: true
    }
  },
  methods: {
    // 表格选中
    handleSelectionChange (val) {
      const SelectionList = val.map(item => item.innerCode)
      Bus.$emit('getpolicy', SelectionList)
    },
    // 计算设备状态
    VmStatus (row, column, cellValue, index) {
      const item = DeviceManagerEnum.DeviceManager.find(
        item => item.id === cellValue
      )
      return item ? item.value : '未投放'
    }
  }
}
</script>

<style lang="scss" scoped>
  .el-table::before {
    height: 0;
  }
  .el-tooltip {
    .el-button--default {
      padding: 12px 0;
      border: 0;
      background-color: transparent;
      margin-right: 10px;
      color: #5f84ff;
    }
  }
</style>
